package com.vencent.spring.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

/**
 * spring提供的EnableWebMvc注解用来代替<mvc:annotation-driven/>
 * @author wbw
 *
 */
@EnableWebMvc
@Configuration
//includeFilters 是在基础包的条件下进一步帅选的， 所以必须加basePackages来约束基础包，如果不指定就默认从本类所在包下查找
//excludeFilters 没有这个限制， 不用加基础包。
@ComponentScan(value="com.vencent.spring", includeFilters=@Filter(type=FilterType.ANNOTATION, value=EnableWebMvc.class), useDefaultFilters=false)
public class WebConfig extends WebMvcConfigurerAdapter{
	@Bean
	public ViewResolver viewResolver(){
		InternalResourceViewResolver resolver = new InternalResourceViewResolver();
		resolver.setPrefix("/WEB-INF/views/");
		resolver.setSuffix(".jsp");
		resolver.setExposeContextBeansAsAttributes(true);
		return resolver;
	}
	
	@Override
	public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
		configurer.enable();
	}
}
